'use strict';

angular.module('app')
  .controller('HomeCtrl', [ '$scope', 'svcMain', 'svcState', function ($scope, svcMain, svcState) {

    svcMain.getLoginDetails().then(function (resp) {
        if (resp.statusCode) {
            if (resp.statusCode == 'SUCCESS') {
                svcState.setLoginUser(resp.object.member);
                $scope.$emit('EVENT.LOGGED_IN');
            }
            else if (resp.statusCode == 'ERROR_LOGIN_REQUIRED') {
                svcState.gotoLogin();
            }
            else {
                console.log(resp.statusCode + (resp.userFriendlyMessage ? ': ' + resp.userFriendlyMessage : ''));
            }

        } else {
            console.log('Invalid response from Server');
        }
    });

  }]);

